define(function(require, exports){
  const $ = require('jquery')
  const THREE = require('three')
  const {
    customPieChart,
    customHistogram,
    customLineChart,
    customHistogramR,
    sleep, tick, getwh, throttle
  } = require('app/func')

  exports.routeIn = function(){
    $('#wrap').addClass('ecart2')
    $('#page-ecart1').hide()
    $('#webgl-bg-round,#webgl-content,.m-overtop,#page-search').hide()
    $('.head-right-time').show()
  }
  exports.routeOut = function(){
    $('#wrap').removeClass('ecart2')
    $('#page-home>*').addClass('fadeOut')
    $('#head-right-search>input').off('keypress')
    $('.searchbtn').off('click')
  }
  function mounted(){
    var height = window.innerHeight * 215 / 1080
    var width  = height
    var loader = new THREE.TextureLoader();
    var scene = new THREE.Scene();
    var camera = new THREE.PerspectiveCamera(30, width / height, 1, 10000);
    camera.position.z = 900;
    var renderer = new THREE.WebGLRenderer({antialias: true, alpha: true});
    renderer.setSize(220, 220);
    var light = new THREE.DirectionalLight(0xffffff, 1);
    light.position.set(0, 0 , 500);
    scene.add(light);
    //地球
    var material = new THREE.MeshPhongMaterial({
      map: loader.load('./img/main-block-1-global-world.png')
    })
    material.transparent = true
    var earth = new THREE.Mesh(
      new THREE.SphereGeometry(180, 35, 35),
      material
    )
    scene.add(earth)
  
    //动画循环
    function render() {
      earth.rotation.y += 0.005;
      renderer.render(scene, camera);
      requestAnimationFrame(render);
    }
    render();
  
    $('#smallearth').append(renderer.domElement);
  }

  function number(num){
    let str = num.toString()
    let arr = []
    while(str.length > 3){
      arr.unshift(str.slice(-3))
      str = str.slice(0,-3)
    }
    if(str) arr.unshift(str)
    return arr.join(',')
  }

  mounted()
  function randomData(){
    let out = {}
    let count = {}
    count.d1 = 0
    count.d2 = 0
    count.d3 = 0
    count.d4 = 0
    count.d5 = 0
    count.d6 = 0
    out.d1 = 0
    out.d2 = 0
    out.d3 = 0
    out.d4 = 0
    out.d5 = 0
    out.d6 = 0
    out.total = 0

    //更新外网
    setInterval(()=>{
      count.d1++
      if(count.d1 == 30){
        count.d1 = 0
        out.d1 += 1
      }
      //更新合作
      count.d2++
      if(count.d2 == 20){
        count.d2 = 0
        out.d2 += 1
      }
      //更新保密
      count.d3++
      if(count.d3 == 1){
        count.d3 = 0
        out.d3 += 1
      }
      count.d4++
      if(count.d4 == 1){
        count.d4 = 0
        out.d4 += 1
      }
      count.d5++
      if(count.d5 == 25){
        count.d5 = 0
        out.d5 += 1
      }
      count.d6++
      if(count.d6 == 13){
        count.d6 = 0
        out.d6 += 1
      }
      //总数
      out.total = out.d1+out.d2+out.d3+out.d4+out.d5+out.d6
      $('#all > div').text(number(out.total))
      $('#ecartnum1').text(number(out.d1))
      $('#ecartnum2').text(number(out.d2))
      $('#ecartnum3').text(number(out.d3))
      $('#ecartnum4').text(number(out.d4))
      $('#ecartnum5').text(number(out.d5))
      $('#ecartnum6').text(number(out.d6))
    },100)
  }
  // randomData()
  function  getwdata(){
    setInterval(async ()=>{
      let res = await  $.get('http://180.97.15.176:8087/api/v1/search/statistics')
      if(res.success){
        let data = res.data
        $('#all > div').text(number(res.total))
        $('#ecartnum1').text(number(data.zh))
        $('#ecartnum2').text(number(data.uk))
        $('#ecartnum3').text(number(data.fr))
        $('#ecartnum4').text(number(data.us))
        $('#ecartnum5').text(number(data.ge))
        $('#ecartnum6').text(number(data.ja))
      }
    },2000)
    
  }
  getwdata()
  
})

